package game;

import util.INIGroup;

public class Portal implements Loadable {

	private int srcX, srcY;
	private int dstX, dstY;
	private TileMap sourceMap = null;
	private TileMap destMap = null;
	private String sourceMapTag = null;
	private String destMapTag = null;
	private String tag = "";
	
	@Override
	public boolean loadFromFile(INIGroup grupa) {
		srcX = grupa.getInteger("srcX");
		srcY = grupa.getInteger("srcY");
		dstX = grupa.getInteger("dstX");
		dstY = grupa.getInteger("dstY");
		sourceMapTag = grupa.getString("SourceMap");
		destMapTag = grupa.getString("DestMap");
		tag = grupa.getString("Tag");
		return true;
	}

	@Override
	public String getTag() {
		return tag;
	}

	@Override
	public void init() {
		sourceMap = GameBase.getMapByTag(sourceMapTag);
		destMap = GameBase.getMapByTag(destMapTag);
		if(sourceMap != null) sourceMap.addPortal(this);
	}

	public int getSrcX() {
		return srcX;
	}

	public int getSrcY() {
		return srcY;
	}

	public int getDstX() {
		return dstX;
	}

	public int getDstY() {
		return dstY;
	}

	public TileMap getSourceMap() {
		return sourceMap;
	}

	public TileMap getDestMap() {
		return destMap;
	}

	public void use(Character c)
	{
		c.setMap(destMap);
		c.setPosX(dstX);
		c.setPosY(dstY);
	}
}
